from fastapi import FastAPI
from starlette.middleware.cors import CORSMiddleware

from apis.routers import v1


def register_router(app: FastAPI):
    """
    路由

    :param app: FastAPI
    :return:
    """
    app.include_router(v1)

    # Extra
    # ensure_unique_route_names(app)


def create_app():
    app = FastAPI(docs_url="/api/v1/docs")

    app.add_middleware(
        CORSMiddleware,
        allow_origins=["*"],  # List of allowed origins
        allow_credentials=True,
        allow_methods=["*"],  # List of allowed methods
        allow_headers=["*"],  # List of allowed headers
    )
    # # 路由
    register_router(app)

    return app